/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webos.java.base.workspace;

import org.webos.java.base.Application;
import org.webos.java.root.RandomGUID;

/**
 *
 * @author kostya
 */
public class Workspace {

    public static final int TYPE_NORMAL = 0;
    public static final int TYPE_FLOAT = 1;
    public static final int POSITION_RIGHT = 0;
    public static final int POSITION_BOTTOM = 1;

    private String caption = null;
    private String code = null;
    private WorkspaceItem item = null;
    private boolean selected = false;
    private Application application = null;
    private boolean closeable = true;

    private int type = TYPE_NORMAL;
    private int direction = POSITION_RIGHT;
    private boolean collapsed = true;
    private int width = 300;
    private int height = 300;

    public Workspace() {
        code = new RandomGUID().toString();
    }

    public Workspace(Application owner, String aCode) {
        code = owner.getCode()+'-'+aCode;
        application = owner;
    }

    public Workspace(Application owner, String aCode, WorkspaceItem aWorkspaceItem) {
        this(owner, aCode);
        setItem(aWorkspaceItem);
    }

    public Application getApplication() {
        return application;
    }

    public void setApplication(Application application) {
        this.application = application;
    }
    
    /**
     * @return the caption
     */
    public String getCaption() {
        return caption;
    }

    /**
     * @param caption the caption to set
     */
    public void setCaption(String caption) {
        this.caption = caption;
        if(application!=null){
            application.workspaceTitleChanged(this);
        }
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @return the item
     */
    public WorkspaceItem getItem() {
        return item;
    }

    /**
     * @param item the item to set
     */
    public void setItem(WorkspaceItem item) {
        this.item = item;
    }

    @Override
    public boolean equals(Object arg0) {
        Workspace ws = (Workspace) arg0;
        return ws.getCode().equals(getCode());
    }

    @Override
    public int hashCode() {
        return 31*getCode().hashCode();
    }

    /**
     * @return the selected
     */
    public boolean isSelected() {
        return selected;
    }

    /**
     * @param selected the selected to set
     */
    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    /**
     * @return the closeable
     */
    public boolean isCloseable() {
        return closeable;
    }

    /**
     * @param closeable the closeable to set
     */
    public void setCloseable(boolean closeable) {
        this.closeable = closeable;
    }

    /**
     * @return the type
     */
    public int getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(int type) {
        this.type = type;
    }

    /**
     * @return the direction
     */
    public int getDirection() {
        return direction;
    }

    /**
     * @param direction the direction to set
     */
    public void setDirection(int direction) {
        this.direction = direction;
    }

    /**
     * @return the collapsed
     */
    public boolean isCollapsed() {
        return collapsed;
    }

    /**
     * @param collapsed the collapsed to set
     */
    public void setCollapsed(boolean collapsed) {
        this.collapsed = collapsed;
    }

    /**
     * @return the width
     */
    public int getWidth() {
        return width;
    }

    /**
     * @param width the width to set
     */
    public void setWidth(int width) {
        this.width = width;
    }

    /**
     * @return the height
     */
    public int getHeight() {
        return height;
    }

    /**
     * @param height the height to set
     */
    public void setHeight(int height) {
        this.height = height;
    }

}
